import React from 'react'
import { HashRouter as Router, Route, Switch, Redirect } from 'react-router-dom'
import { requireLogin } from '@/routes/routerUtils'
import NotFound from '@/pages/NotFound'
import Login from '@/pages/Login'
import App from './App/App'

export default () => (
  <Router>
    <Switch>
      <Route exact path="/" render={() => <Redirect to="/app/home" push />} />
      <Route path="/app" component={App} />
      <Route path="/404" component={NotFound} />
      <Route
        path="/login"
        render={(props): React.ReactElement => {
          const isLogin = requireLogin(props)
          if (isLogin) {
            console.info('已登录从定向到首页')
            return <Redirect to={'/'} />
          } else {
            console.info('未登录展示登录页')
            return <Login {...props} />
          }
        }}
      />
      <Route component={NotFound} />
    </Switch>
  </Router>
)
